package com.netty.chapter05;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
@Slf4j
public class TestNettyFuture {
    public static void main(String[] args) {
        NioEventLoopGroup group=new NioEventLoopGroup();
        EventLoop loop = group.next();
        Future<Integer> future = loop.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.info("开始计算结果");
                Thread.sleep(2000);
                return 1000;
            }
        });
        future.addListener(new GenericFutureListener<Future<? super Integer>>() {
            @Override
            public void operationComplete(Future<? super Integer> future) throws Exception {

                log.info("得到的结果为：{}",future.getNow());
                group.shutdownGracefully();
            }
        });
    }
}
